package service.impl;



import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import common.dao.BookTypeMapper;
import common.pojo.BookType;
import common.utils.Constants;


@Service
public class BookTypeServiceImpl {


	@Autowired
    private BookTypeMapper mapper;

	/**
	 * 查询数量
	 * @param bType
	 * @return
	 */
	public int queryByCount(BookType bType) {
		return mapper.queryByCount(bType);
	}
	
	/**
	 * 查询列表
	 * @return
	 */
	public List<BookType> find() {
		return mapper.queryListByWhere("where deleted="
				+ Constants.NOT_DELETED + " order by create_time desc");
	}
	
	/**
	 * 查询列表
	 * @param start
	 * @param limit
	 * @return
	 */
	public List<BookType> find(int start, int limit) {
		return mapper.queryListByWhere("where deleted="
				+ Constants.NOT_DELETED + " order by create_time desc limit "
				+ start + "," + limit);
	}

	/**
	 * 删除类型
	 * @param ids
	 * @param adminName
	 */
	public void delete(String ids, String adminName) {
		String[] id = StringUtils.split(ids, ",");
		BookType bType = new BookType();
		for (int i = 0; i < id.length; i++) {
			if (StringUtils.isNotBlank(id[i])) {
				bType.setDeleted(Constants.DELETED);
				bType.setUpdateName(adminName);
				bType.setUpdateTime(new Date());
				bType.setId(Integer.valueOf(id[i]));
				mapper.updateBySelective(bType);
			}
		}
	}

	/**
	 * 增加
	 * @param bType
	 */
	public void add(BookType bType) {
		bType.setState(Constants.SHOW);
		bType.setDeleted(Constants.NOT_DELETED);
		mapper.add(bType);
	}

	/**
	 * 查询
	 */
	public BookType findInfoById(String id) {		
		return mapper.queryById(Integer.parseInt(id));
	}

	/**
	 * 更新
	 * @param bType
	 */
	public void update(BookType bType) {
		mapper.updateBySelective(bType);
	}

	
}
